package de.lulusoft.anothertorrent.core.xmlrpc;

import org.apache.ws.commons.util.NamespaceContextImpl;
import org.apache.xmlrpc.common.TypeFactoryImpl;
import org.apache.xmlrpc.common.XmlRpcController;
import org.apache.xmlrpc.common.XmlRpcStreamConfig;
import org.apache.xmlrpc.parser.TypeParser;
import org.apache.xmlrpc.parser.I8Parser;
import org.apache.xmlrpc.serializer.TypeSerializer;
import org.xml.sax.SAXException;


public class RTorrentTypeFactory extends TypeFactoryImpl {
	
	private static final String P_I8 = "i8";

	public RTorrentTypeFactory(XmlRpcController controller) {
		super(controller);
	}
	
	@Override
    public TypeParser getParser(XmlRpcStreamConfig pConfig,
      NamespaceContextImpl pContext, String pURI, String pLocalName) {

        if (P_I8.equals(pLocalName)) {
            return new I8Parser();
        } else {
            return super.getParser(pConfig, pContext, pURI, pLocalName);
        }
    }

	@Override
	public TypeSerializer getSerializer(XmlRpcStreamConfig config, Object object)
			throws SAXException {
		if (object instanceof Long)
			return new CustomI8Serializer();
		else
			return super.getSerializer(config, object);
	}
	
	
}
